<%--  获取index.jsp页面传递进来的数据  --%>
<%  String id = request.getParameter("stuid"); %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<%@page import="java.sql.*"%>
<% request.setCharacterEncoding("utf-8");%>
<%  String stuName = request.getParameter("stuname"); %>
<%  String stuBirthday = request.getParameter("stubirthday"); %>
<%  String stuClass = request.getParameter("stuclass"); %>
<head>
    <meta charset="UTF-8">
    <title>修改结果</title>
    <%!
        ResultSet rs;//数据库查询结果集对象
    %>
    <%
        String dbName = "studb";//数据库名称
        String userName ="root";//账号
        String userPasswd = "qq18838473683";//密码
        //自己电脑IP是127.0.0.1或者localhost
        String url = "jdbc:mysql://locahost:3306/"+ dbName+ "?user"+userName+"&password="+userPasswd;
        Class.forName("com.mysql.jdbc.Driver");//8.0带.cj  5.7以下不带
        Connection conn = DriverManager.getConnection(url);//连接数据库
        String sql = "update student set birthday=?,stuclass=?where number=?";
        PreparedStatement preparedStatement=conn.prepareStatement(sql);
        preparedStatement.setString(1,stuBirthday);
        preparedStatement.setString(2,stuClass);
        preparedStatement.setString(3,id);
        int result=preparedStatement.executeUpdate();
        if(result>0)
            out.print(" <script type='text/javascript'>alert('修改成功');</script>");
        else
            out.print(" <script type='text/javascript'>alert('修改失败');</script>");
        sql="select *from student";
        rs = preparedStatement.executeQuery(sql);//执行查询操作
    %>
</head>
<body>
<table border="1">
    <th colspan="4" style="font-size: x-large; alignment:center";>学生表信息</th>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>所在班级</td>
    </tr>
    <%-- 循环查询结果集    --%>
    <% while (rs.next()){ %>
    <%-- 使用表达式显示结果集中对应的列值        --%>
    <tr style="text-align: center">
        <td><%=rs.getString(1) %></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString("birthday")%></td>
        <td><%= rs.getString("stuclass")%></td>
    </tr>
    <% } %>
    <%--   查询结束 关闭结果集，student对象和数据库连接    --%>
    <%
        rs.close();
        preparedStatement.close();
        conn.close();
    %>
</table>
</body>
</html>